package export.microshop
{
	import com.game.data.vo.PlayerDataVO;
	import com.game.event.GameEvent;
	import com.game.manager.NotificationManager;
	import com.game.view.component.notification.TipBox;
	
	import config.Config;
	
	import flash.events.*;
	
	public class BuyThingCmd
	{
		
		public function BuyThingCmd(param1:int, param2:int, param3:int, param4:String, param5:String, param6:PlayerDataVO)
		{
			super();
			this.gc = Config.getIns();
			this.allmoney = param1;
			this.setTnum(param3);
			this.tname = param4;
			this.setPrice(param2);
			this.color = param5;
			this.player = param6;
			init();
			
		}
		
		private var player:PlayerDataVO;
		private var gc:Config;
		private var tname:String;
		private var price1:int;
		private var price2:int;
		private var tnum1:int;
		private var tnum2:int;
		private var color:String;
		private var allmoney:int;
		
		private function init():void
		{
			var _loc1_:TipBox = new TipBox("", this.okClick, this.changeClick);
			_loc1_.setText("你确定要购买" + this.getTnum() + "个" + this.tname + "总共花费" + Number(this.getPrice()) * Number(this.getTnum()) + "灵魂?");
			_loc1_.add();
		}
		
		private function destory():void
		{
			this.setPrice(0);
			this.setTnum(0);
		}
		
		private function setPrice(param1:int):void
		{
			var _loc2_:int = Math.round(Math.random() * 500);
			this.price1 = param1 - _loc2_;
			this.price2 = _loc2_;
		}
		
		private function getPrice():int
		{
			var _loc1_:int = this.price1 + this.price2;
			if (this.gc.userData.maxStage > 2)
			{
				_loc1_ = int(_loc1_ * 0.8);
			}
			return _loc1_;
		}
		
		private function setTnum(param1:int):void
		{
			var _loc2_:int = Math.round(Math.random() * 500);
			this.tnum1 = param1 - _loc2_;
			this.tnum2 = _loc2_;
		}
		
		private function getTnum():int
		{
			return this.tnum1 + this.tnum2;
		}
		
		private function changeClick(param1:MouseEvent):void
		{
			this.gc.eventManager.dispatchEvent(new Event("BUYCHANGLE"));
			this.destory();
		}
		
		private function okClick(param1:MouseEvent):void
		{
			var _loc2_:int = int(this.player.lhValue);
			Micropayment.needLh = Number(this.getPrice()) * Number(this.getTnum());
			if (_loc2_ >= Micropayment.needLh)
			{
				this.gc.eventManager.dispatchEvent(new GameEvent("BuySuccess", [0]));
				NotificationManager.alert("购买成功！");
			}
			else
			{
				NotificationManager.alert("灵魂不足！");
				this.gc.eventManager.dispatchEvent(new Event("BUYCHANGLE"));
			}
			this.destory();
		}
	}
}
